package com.he.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.he.mapper.AirQualityIndexMapper;
import com.he.pojo.AirQualityIndex;
import com.he.service.AirQualityIndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AirQualityIndexServiceImpl extends
        ServiceImpl<AirQualityIndexMapper, AirQualityIndex> implements AirQualityIndexService {

    @Autowired
    private AirQualityIndexMapper airQualityIndexMapper;

    @Override
    public List<AirQualityIndex> findAirQualityIndex() {
        return airQualityIndexMapper.selectList(null);
    }

    @Override
    public Integer addAirQualityIndex(AirQualityIndex airQualityIndex) {
        return airQualityIndexMapper.insert(airQualityIndex);
    }

    @Override
    public AirQualityIndex findAirQualityIndexById(Integer id) {
        return airQualityIndexMapper.selectById(id);
    }

    @Override
    public Integer updateData(AirQualityIndex airQualityIndex) {
        return airQualityIndexMapper.updateById(airQualityIndex);
    }

    /**
     * 通过区域查询数据
     * @param district 区域
     * @return 数据
     */
    @Override
    public List<AirQualityIndex> selectByDistrict(String district) {
        // 如果区域为空测查询所有
        if ("不限".equals(district)) {
            return airQualityIndexMapper.selectList(null);
        }
        QueryWrapper<AirQualityIndex> wrapper = new QueryWrapper<>();
        wrapper.eq("district",district);
        return airQualityIndexMapper.selectList(wrapper);
    }
}
